.class public Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;
.super Ljava/lang/Thread;
.source "UsbSerialDevice.java"


# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/felhr/usbserial/UsbSerialDevice;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x4
    name = "WorkerThread"
.end annotation


# instance fields
.field private callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

.field private requestIN:Landroid/hardware/usb/UsbRequest;

.field final synthetic this$0:Lcom/felhr/usbserial/UsbSerialDevice;

.field private usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

.field private working:Ljava/util/concurrent/atomic/AtomicBoolean;


# direct methods
.method public constructor <init>(Lcom/felhr/usbserial/UsbSerialDevice;Lcom/felhr/usbserial/UsbSerialDevice;)V
    .locals 0

    .line 224
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    invoke-direct {p0}, Ljava/lang/Thread;-><init>()V

    .line 225
    iput-object p2, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    .line 226
    new-instance p1, Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 p2, 0x1

    invoke-direct {p1, p2}, Ljava/util/concurrent/atomic/AtomicBoolean;-><init>(Z)V

    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    return-void
.end method

.method private onReceivedData([B)V
    .locals 1

    .line 281
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    if-eqz v0, :cond_0

    .line 282
    invoke-interface {v0, p1}, Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;->onReceivedData([B)V

    :cond_0
    return-void
.end method


# virtual methods
.method public getUsbRequest()Landroid/hardware/usb/UsbRequest;
    .locals 1

    .line 276
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->requestIN:Landroid/hardware/usb/UsbRequest;

    return-object v0
.end method

.method public run()V
    .locals 3

    .line 232
    :cond_0
    :goto_0
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicBoolean;->get()Z

    move-result v0

    if-eqz v0, :cond_3

    .line 234
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v0, v0, Lcom/felhr/usbserial/UsbSerialDevice;->connection:Landroid/hardware/usb/UsbDeviceConnection;

    invoke-virtual {v0}, Landroid/hardware/usb/UsbDeviceConnection;->requestWait()Landroid/hardware/usb/UsbRequest;

    move-result-object v0

    if-eqz v0, :cond_0

    .line 235
    invoke-virtual {v0}, Landroid/hardware/usb/UsbRequest;->getEndpoint()Landroid/hardware/usb/UsbEndpoint;

    move-result-object v1

    invoke-virtual {v1}, Landroid/hardware/usb/UsbEndpoint;->getType()I

    move-result v1

    const/4 v2, 0x2

    if-ne v1, v2, :cond_0

    .line 236
    invoke-virtual {v0}, Landroid/hardware/usb/UsbRequest;->getEndpoint()Landroid/hardware/usb/UsbEndpoint;

    move-result-object v0

    invoke-virtual {v0}, Landroid/hardware/usb/UsbEndpoint;->getDirection()I

    move-result v0

    const/16 v1, 0x80

    if-ne v0, v1, :cond_0

    .line 238
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v0, v0, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v0}, Lcom/felhr/usbserial/SerialBuffer;->getDataReceived()[B

    move-result-object v0

    .line 242
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    invoke-static {v1}, Lcom/felhr/usbserial/UsbSerialDevice;->access$000(Lcom/felhr/usbserial/UsbSerialDevice;)Z

    move-result v1

    if-eqz v1, :cond_1

    .line 244
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    check-cast v1, Lcom/felhr/usbserial/FTDISerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/FTDISerialDevice;->ftdiUtilities:Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;

    invoke-virtual {v1, v0}, Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;->checkModemStatus([B)V

    .line 245
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v1}, Lcom/felhr/usbserial/SerialBuffer;->clearReadBuffer()V

    .line 247
    array-length v1, v0

    if-le v1, v2, :cond_2

    .line 249
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->usbSerialDevice:Lcom/felhr/usbserial/UsbSerialDevice;

    check-cast v1, Lcom/felhr/usbserial/FTDISerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/FTDISerialDevice;->ftdiUtilities:Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;

    invoke-virtual {v1, v0}, Lcom/felhr/usbserial/FTDISerialDevice$FTDIUtilities;->adaptArray([B)[B

    move-result-object v0

    .line 250
    invoke-direct {p0, v0}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->onReceivedData([B)V

    goto :goto_1

    .line 255
    :cond_1
    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v1}, Lcom/felhr/usbserial/SerialBuffer;->clearReadBuffer()V

    .line 256
    invoke-direct {p0, v0}, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->onReceivedData([B)V

    .line 259
    :cond_2
    :goto_1
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->requestIN:Landroid/hardware/usb/UsbRequest;

    iget-object v1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->this$0:Lcom/felhr/usbserial/UsbSerialDevice;

    iget-object v1, v1, Lcom/felhr/usbserial/UsbSerialDevice;->serialBuffer:Lcom/felhr/usbserial/SerialBuffer;

    invoke-virtual {v1}, Lcom/felhr/usbserial/SerialBuffer;->getReadBuffer()Ljava/nio/ByteBuffer;

    move-result-object v1

    const/16 v2, 0x4000

    invoke-virtual {v0, v1, v2}, Landroid/hardware/usb/UsbRequest;->queue(Ljava/nio/ByteBuffer;I)Z

    goto :goto_0

    :cond_3
    return-void
.end method

.method public setCallback(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)V
    .locals 0

    .line 266
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->callback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    return-void
.end method

.method public setUsbRequest(Landroid/hardware/usb/UsbRequest;)V
    .locals 0

    .line 271
    iput-object p1, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->requestIN:Landroid/hardware/usb/UsbRequest;

    return-void
.end method

.method public stopWorkingThread()V
    .locals 2

    .line 287
    iget-object v0, p0, Lcom/felhr/usbserial/UsbSerialDevice$WorkerThread;->working:Ljava/util/concurrent/atomic/AtomicBoolean;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Ljava/util/concurrent/atomic/AtomicBoolean;->set(Z)V

    return-void
.end method
